home *** CD-ROM | disk | FTP | other *** search
- Path: airdmhor.gen.nz!not-for-mail
- From: gumboot@airdmhor.gen.nz (Simon Hosie)
- Newsgroups: comp.lang.c
- Subject: Re: division problem
- Date: 30 Jan 1996 05:14:50 +1300
- Organization: Airdmhor
- Message-ID: <4eirpq$8ut@airdmhor.gen.nz>
- References: <31097D77.11AA@rain.org>
- NNTP-Posting-Host: localhost.gen.nz
- X-Newsreader: TIN [version 1.2 PL2]
-
- tpaul:
- > Can anyone show me why this does not work? I am a beginner.
-
- 1> #include <stdio.h>
-
- 3> main ()
- 4> {
- 5> int fahrenheit, celsius;
-
- 7> printf("Fahrenheit temperature =?";
- 8> scanf("%d",fahrenheit);
- 9> celsius = 5/9*(fahrenheit-32);
- 10> printf("Fahrenheit = %d, Celsius = %d", fahrenheit, celsius;
- 11> }
-
- I don't know if the guy I told off answered this (I just looked at his
- answer and got upset). Firstly you don't have any closing brackets on your
- printf()'s, secondly..
-
- I can't quite remember how C chooses the types to use, I think it's the
- first thing after the '='.. anyway, it's doing integer math. The first
- thing it does is divide 5 by 9, that gives 0 (the remainder is thrown away)
- then it multiplies (fahrenheight - 32) by 0.
-
- The solution is to do your multiplies first. The solution is _not_ to use
- floating point.
-